import { Form, type FormInstance } from 'antd';
import dayjs from 'dayjs';
import type React from 'react';
import { useEffect } from 'react';
import TradeInfoForm from '../TradeInfoForm.tsx';

interface EditTradeInfoFormProps {
  trade: any;
  form: FormInstance;
}

const EditTradeInfoForm: React.FC<EditTradeInfoFormProps> = ({
  trade,
  form,
}) => {
  useEffect(() => {
    form.setFieldsValue({ ...trade, tradeDate: dayjs(trade.tradeDate) });
  }, [trade, form]);

  return (
    <Form
      form={form}
      layout="vertical"
      initialValues={{ ...trade, tradeDate: dayjs(trade.tradeDate) }}
    >
      <TradeInfoForm />
    </Form>
  );
};

export default EditTradeInfoForm;
